package com.pactera.jep.service.yapin.accident.controller;

import com.pactera.jep.orm.Filter;
import com.pactera.jep.orm.Order;
import com.pactera.jep.orm.Page;
import com.pactera.jep.service.yapin.accident.model.Accident;
import com.pactera.jep.service.yapin.accident.service.AccidentService;
import com.pactera.jep.web.controller.CrudController;
import com.pactera.jep.web.entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 *
 * @Author YouName
 * @Date Aug 5, 2020 4:20:16 PM
 */
@RestController
@RequestMapping("/accident")
@Api(description = "押品意外信息")
public class AccidentController extends CrudController<Accident> {

    @Autowired
    AccidentService accidentService;

    @GetMapping("/{id}")
    @ApiOperation("查询押品意外信息")
    public Result get(@PathVariable("id") String accidentinfoId) {
        return Result.success(accidentService.get(accidentinfoId));
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除押品意外信息")
    public Result delete(@PathVariable("id") String accidentinfoId) {
        return Result.success(accidentService.deleteByPrimaryKey(accidentinfoId));
    }

    @PostMapping("/save")
    @ApiOperation("插入押品意外信息")
    public Result insert(@RequestBody Accident accident) {
        return Result.success(accidentService.insert(accident));
    }

    @PostMapping("/update")
    @ApiOperation("更新押品意外信息")
    public Result update(@RequestBody Accident accident) {
        return Result.success(accidentService.update(accident));
    }

    /**
     * 为列表页面做数据准备
     */
    @Override
    protected void prepareQuery(Page<Accident> page, List<Filter> filters, List<Order> orders, HttpServletRequest    request) {
        accidentService.query(page, filters, orders);
    }
}
